home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group01b.txt
/
000166_icon-group-sender_Thu Nov 8 16:50:37 2001.msg
< prev
next >
Wrap
Internet Message Format
|
2002-01-03
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id fA8NnBA06365
for icon-group-addresses; Thu, 8 Nov 2001 16:49:11 -0700 (MST)
Message-Id: <200111082349.fA8NnBA06365@baskerville.CS.Arizona.EDU>
Date: Thu, 08 Nov 2001 14:08:12 -0700
From: Steve Wampler <swampler@noao.edu>
X-Accept-Language: en
To: Taybin Rutkin <trutkin@physics.clarku.edu>
CC: icon-group@cs.arizona.edu
Subject: Re: mutual evaluation
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2300
Taybin Rutkin wrote:
>
> On Thu, 8 Nov 2001, Steve Wampler wrote:
>
> > The idiom in use in these mutual evaluation examples is simple:
> >
> > return 2(initialize, compute, cleanup)
> >
> > which is really pretty clean - most of the time. It's not clean
> > when any of initialize, compute, or cleanup is complex (but *that*
> > can often be solved by encapsulating the complex action in a
> > procedure).
>
> Is 2() a standard library procedure? I don't think I've seen it
> before. I didn't know that procedures could have a digit as a name. How
> does it work?
Ah, mutual evaluation is an Icon language expression evaluation feature, not a
procedure. It's covered starting on page 72 of the 3rd ed. of the Icon
programming language (and probably appears in all the earlier books - it's been
around a while... look for mutual evaluation in the index). It actually helps
illustrate how general Icon's expression evaluation mechanims is.
The expression syntax:
expr0(expr1,expr2,...,exprN)
has a couple of uses. If expr0 evaluates to a function or procedure name
then that function/procedure is invoked (after evaluating the arguments
of course!). If expr0 evaluates to an integer, then the arguments are
evaluated and the whole expression returns the result produced by the argument
in the position represented by that integer. [Since expr0 evaluates to
a "position", 0 means to produce the result of the last argument and
omitting expr0 defaults it to 0.]
So, for example:
write( 1("a","b","c") )
would output "a", while
write( 3("a","b","c") )
would output "c", and
write( ("a","b","c") )
also outputs "c".
Naturally, being Icon, any/all of the expressions can be
arbitrarily complex. For example, there's nothing other
than a programmer's common sense keeping expr0 be
a generator that produces both integers *and* function/
procedure names... (very hard to think of a valid use for
that one!)
As an aside, it might have been cleaner if I had written:
return 3(f := open(fName), seek(f,0), where(f)-1, close(f))
instead of
return 2(f := open(fName), where(seek(f,0))-1, close(f))
in the previous message, since the first more clearly shows
the steps involved.
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu